#include <cstdio>
#include <queue>
#include <cstring>
#include <stack>

#define INF 100000000000000LL
using namespace std;

char s[ 5001 ];
int head[ 5001 ], node[ 20001 ], next[ 20001 ];
long long d[ 5001 ];
int r, c, cost, st, ed, p, e;

void addedge( int u, int v )
{
    node[ e ] = v; next[ e ] = head[ u ]; head[ u ] = e++;
}

void init( )
{
    int i, j;
    bool flag = false;
    for ( i = 0; i < r; i++ )
        scanf("%s", s + i * c);
    e = 0;
    p = -1;
    memset( head, -1, sizeof( head ) );
    for ( i = 0; i < r; i++ )
        for ( j = 0; j < c; j++ )
        {
            if ( s[ i * c + j ] == '#' ) continue;
            if ( s[ i * c + j ] == 'P' )
            {
                if ( !flag )
                {
                    flag = 1;
                    p = i * c + j;
                }
                if ( j && s[ i * c + j - 1 ] != '#' && s[ i * c + j - 1 ] != 'P' )
                {
                    addedge( p, i * c + j - 1 );
                    addedge( i * c + j - 1, p );
                }
                if ( i && s[ ( i - 1 ) * c + j ] != '#' && s[ ( i - 1 ) * c + j ] != 'P' )
                {
                    addedge( p, ( i - 1 ) * c + j );
                    addedge( ( i - 1 ) * c + j, p );
                }
                continue;
            }
            if ( s[ i * c + j ] == 'Y' )
                st = i * c + j;
            if ( s[ i * c + j ] == 'C' )
                ed = i * c + j;
            if ( i && s[ ( i - 1 ) * c + j ] != '#' )
            {
                if ( s[ ( i - 1 ) * c + j ] == 'P' )
                {
                    addedge( i * c + j, p );
                    addedge( p, i * c + j );
                }
                else
                {
                    addedge( i * c + j, ( i - 1 ) * c + j );
                    addedge( ( i - 1 ) * c + j, i * c + j );
                }
            }
            if ( j && s[ i * c + j - 1 ] != '#' )
            {
                if ( s[ i * c + j - 1 ] == 'P' )
                {
                    addedge( i * c + j, p );
                    addedge( p, i * c + j );
                }
                else
                {
                    addedge( i * c + j, i * c + j - 1 );
                    addedge( i * c + j - 1, i * c + j );
                }
            }
        }
    for ( i = 0; i < r * c; i++ ) d[ i ] = INF;
    d[ st ] = 0;
}

queue<int> q;
bool visit[ 5001 ];
int pi[ 5001 ];

void work( )
{
    int i, u, v, w;
    memset( visit, 0, sizeof( visit ) );
    memset( pi, -1, sizeof( pi ) );
    q.push( st );
    while ( !q.empty( ) )
    {
        u = q.front( );
        q.pop( );
        visit[ u ] = 0;
        for ( i = head[ u ]; i != -1; i = next[ i ] )
        {
            v = node[ i ];
            if ( s[ v ] != '*' )
                w = 0;
            else
                w = cost;
            if ( d[ v ] > d[ u ] + w )
            {
                pi[ v ] = u;
                d[ v ] = d[ u ] + w;
                if ( !visit[ v ] )
                {
                    visit[ v ] = 1;
                    q.push( v );
                }
            }
        }
    }
    if ( d[ ed ] == INF )
        puts("Damn teoy!");
    else
        printf("%I64d\n", d[ ed ]);
}

int main( )
{
    while ( scanf("%d%d%d", &r, &c, &cost) != EOF )
    {
        init( );
        work( );
    }
    return 0;
}
